<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html;charset=utf-8" pageEncoding="utf-8"
	language="java"%>
<%@ include file="/jsp/platform/include/include.jsp"%>
<html>
<head>
<TITLE><c:out value="${_LOGONUSER_.MANAGETITILE}" /></TITLE>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<%@ include file="/jsp/platform/include/header.jsp"%>
	<script type="text/javascript">
	        $(document).ready(function() {

	          //循环角色
			   var trHtml = '<tr><td width="200"><label for="c_1" class="cAll">'+
				                '<input name="" type="checkbox" value="" id="c_1">所有角色</label></td>';
				   //其次是具体菜单
				   trHtml = trHtml+'<td>';
				   <c:forEach items="${allRoles}" var="allRole">
				      var roleId = '${allRole.roleId}';
				      var roleName = '${allRole.roleName}';
				         trHtml = trHtml +'<label for="c_1_"'+roleId+'>';
				         trHtml = trHtml +'<input name="action_code" type="checkbox" value="'+roleId+'" id="role_'+roleId+'">'+roleName+'</label>';
				   </c:forEach>
				   trHtml = trHtml+'</td>';             
				   trHtml = trHtml+'</tr>';
	               $("#roleTable").append(trHtml);
	               
	          //初始化关联的菜单
	          <c:forEach items="${roleList}" var="selectRole">
	             var roleId = '${selectRole.roleId}';
	             $("#role_"+roleId).attr("checked",true);
	          </c:forEach> 
	          //start 设置全选相关操作事件
	          $("#eAll").change(function(){
		        $(".choose_list input:checkbox").attr("checked",$(this).attr("checked"))
		      })
		      $(".choose_list input:checkbox").change(function(){
		        var pp = $(this).parent().parent();
		        if ($(pp).index()==0){
		          $(pp).parent().find("input:checkbox").attr("checked",$(this).attr("checked"))
		        }else{
		          var dl = $(pp).find("input:checked").length;
		          var cl = $(pp).find("input:checkbox").length;
		          if (dl==cl){
		            $(pp).prev().find("input:checkbox").attr("checked",true)
		          }else{
		            $(pp).prev().find("input:checkbox").attr("checked",false)
		            
		          }
		        }
		        var adl = $(".choose_list input:checked").length;
		        var acl = $(".choose_list input:checkbox").length;
		        if(adl==acl){
		          $("#eAll").attr("checked",true)
		        }else{
		          $("#eAll").attr("checked",false)            
		        }
		      })
		      //end 设置全选相关操作事件
            })
            //设置角色菜单关联
		    function setOperatorInfoRoles() {
			    $.messager.confirm("操作提示", "您确定要执行此操作吗！", function (data) {
			           if(data){
			                 var action_code = $("input[name^='action_code']");
			                 var selectRole = "";
			                 for(i=0;i<action_code.length;i++){
			                    var isOrNotChecked = action_code[i].checked;
			                    if(isOrNotChecked){
			                       selectRole = selectRole+action_code[i].value+";";
			                    }
			                 }
			                 var url = '<%=request.getContextPath()%>/manage/operatorInfo/setOperatorInfoRoles';
									$.post(
									       url,
										   {
												'operatorId' : $("#operatorId").val(),
												'roleIds': selectRole
											},
											function(data) {
												if (data.success) {
													$.messager
															.alert(
																	"提示信息",
																	data.msg,
																	"info",
																	function() {
																		window.location.href = window.location.href;
																	});
												} else {
													$.messager.alert(
															"提示信息",
															data.msg);
												}
											});
								}
							});
		}
	</script>
</HEAD>
<BODY>
	<DIV class="all">
		<%@ include file="/jsp/platform/include/head.jsp"%>
		<%@ include file="/jsp/platform/include/menu.jsp"%>
		<DIV class="mains">
			<TABLE width="100%" border="0" cellspacing="0" cellpadding="0">
				<TBODY>
					<TR valign="top">
						<%@ include file="/jsp/platform/include/mainLeft.jsp"%>
						<TD>
							<TABLE width="100%" border="0" cellspacing="0" cellpadding="0">
								<TBODY>
									<TR>
										<TD>
											<TABLE width="180" border="0" cellspacing="0" cellpadding="0">
												<TBODY>
													<TR>
														<TD width="7"><IMG width="7" height="36" alt=""
															src="<%=request.getContextPath()%>/images/pages_l.jpg">
														</TD>
														<TD align="center"
															background="<%=request.getContextPath()%>/images/pages_bg.jpg">
															<SPAN class="f_tit1">设置角色</SPAN></TD>
														<TD width="7"><IMG width="7" height="36" alt=""
															src="<%=request.getContextPath()%>/images/pages_r.jpg">
														</TD>
													</TR>
												</TBODY>
											</TABLE></TD>
									</TR>
								</TBODY>
								<TR>
									<TD>
										<div class="pages_con">
											<div class="pages_con_20">
												<div class="transaction_external padding_b_0">
													<form name="queryForm" id="queryForm" method="post"
														action="<%=request.getContextPath()%>/manage/roles/editRoleMenus">
														<div class="clearfix">
															<span class="label margin_l_10" style="margin-left:70px;">操作员:</span>
															<span class="label margin_l_10"> <input type="hidden" id="operatorId" value="<c:out value='${model.operatorId}' />"><c:out value='${model.operatorName}' /> </span> 
														</div>
														<div class="clear">&nbsp;</div>
													</form>
												</div>

												<form method="post" name="operForm3"
													action="/buser/MOPER/0300/1/update">
													<div class="transaction_external">
														<div class="choose_all" style="padding-left:20px;">
															 <a class="btn confirm margin_l_30"
																href="javascript:void(0);" onClick="setOperatorInfoRoles()">保存</a>
														</div>
														<div class="choose_all choose_list"
															style="padding-left:20px;">
															<table width="100%" id="roleTable" name="roleTable">
																
															</table>
														</div>
													</div>
													<input type="hidden" name="selectRole" id="selectRole" value="">
												</form>
												<div class="clear">&nbsp;</div>
											</div>
											<!--当中内容块结束-->
									</TD>
								</TR>
							</TABLE></TD>
					</TR>
				</TBODY>
			</TABLE>
		</DIV>
		<TABLE width="100%" border="0" cellspacing="0" cellpadding="0">
			<TBODY>
				<TR>
					<TD width="5" bgcolor="#f1fcfe"><IMG width="5" height="5"
						src="<%=request.getContextPath()%>/images/footer_l.jpg">
					</TD>
					<TD bgcolor="#f1fcfe">&nbsp; <br />
					</TD>
					<TD width="5" bgcolor="#f1fcfe"><IMG width="5" height="5"
						src="<%=request.getContextPath()%>/images/footer_r.jpg">
					</TD>
				</TR>
			</TBODY>
		</TABLE>
		<%@ include file="/jsp/platform/include/foot.jsp"%>
</BODY>
</HTML>
